﻿# 此脚本在服务器运行
import socket

from multiprocessing import Process

ip = "x.x.x.x"  #此处填入你服务器的内网ip



# ip = "127.0.0.1"


def handleClient(clientSocket):
    recvData = clientSocket.recv(2014)
    requestHeaderLines = recvData.splitlines()
    for line in requestHeaderLines:
        print(line)

    responseHeaderLines = "HTTP/1.1 200 OK\r\n"
    responseHeaderLines += "\r\n"
    responseBody = "Software Started！"

    response = responseHeaderLines + responseBody
    clientSocket.send(response.encode())
    clientSocket.shutdown(2)
    clientSocket.close()


def main():
    serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serverSocket.bind((ip, 7788))
    serverSocket.listen(10)
    c, addr = s.accept()
    print(addr, "Connected!")
    flag = True
    while True:
        clientSocket, clientAddr = serverSocket.accept()
        print(clientAddr, "Connected!")
        clientP = Process(target=handleClient, args=(clientSocket,))
        clientP.start()

        c.send("Received!".encode())

        clientSocket.close()



if __name__ == '__main__':
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((ip, 7777))
    s.listen(10)
    print("Listening...")
    main()


